//
//  MyCollectMsgViewController.m
//  家校互通
//
//  Created by 李赛 on 15/6/15.
//  Copyright (c) 2015年 姬鑫宇. All rights reserved.
//

#import "MyCollectMsgViewController.h"
#import "MyCollectionTableViewCell.h"
#import "BLActivityDetailViewController.h"
#import "HomeWorkViewController.h"
#import "PayViewController.h"
@interface MyCollectMsgViewController ()<UITableViewDataSource, UITableViewDelegate,ConnectControlDelegate>{
    ConnectControl *connectCtr;
    UILabel *infoLB;
}
@property (nonatomic, retain) NSMutableArray *titleArray;
@property (nonatomic, retain) NSArray *collectArray;
@end

@implementation MyCollectMsgViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _contentTableView.delegate=self;
    _contentTableView.dataSource=self;
//    _contentTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    [_contentTableView reloadData];
    
    connectCtr = [ConnectControl showForView:self.view];
    connectCtr.delegate=self;
    
    if (connectCtr.superview!=nil && connectCtr.loading==NO)
    {
        [connectCtr setLoading:YES];
    }

    // Do any additional setup after loading the view.
}

-(void)connect{
    [DSFUserInfo getMyCollects:^(BOOL result, NSArray *classUserArr, NSError *error) {
        [ConnectControl removeFromView:self.view];
        _collectArray = [NSArray arrayWithArray:classUserArr];
        [_contentTableView reloadData];
        if (classUserArr.count == 0) {
            infoLB = [[UILabel alloc]initWithFrame:CGRectMake(0,0,70,30)];
            infoLB.center = CGPointMake(DSF_SCREENWIDTH/2, DSF_SCREENHEIGHT/2);
            infoLB.textColor = [UIColor darkGrayColor];
            infoLB.text = @"暂无收藏";
            infoLB.textAlignment = NSTextAlignmentCenter;
            infoLB.font = [UIFont systemFontOfSize:15.0f];
            infoLB.backgroundColor = [UIColor clearColor];
            [self.view addSubview:infoLB];
        }
    } withPageNumber:0 withPageSize:20];
}

#pragma mark -UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _collectArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CollectModel *model = [_collectArray objectAtIndex:indexPath.row];
    MyCollectionTableViewCell *vCell=[tableView dequeueReusableCellWithIdentifier:@"MyCollectionTableViewCell" forIndexPath:indexPath];
    if (indexPath.row%2) {
        vCell.backgroundColor=[UIColor clearColor];
    }else
    {
        vCell.backgroundColor=[UIColor whiteColor];
    }
    [vCell setContentOfCollectModel:model];
    return vCell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
#pragma mark -UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.001;;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}
// Called after the user changes the selection.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CollectModel *model = [_collectArray objectAtIndex:indexPath.row];
    if (model.type == kBlackBoardActivity)
    {
        BLActivityDetailViewController *vc = [self.storyboard  instantiateViewControllerWithIdentifier:@"BLActivityDetailViewController"];
        vc.activityId = model.id;
        AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
    }
    else if (model.type == kBlackBoardPay)
    {
        PayViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"PayViewController"];
        vc.title=@"支付";
        //        vc.hasPayfees=indexPath.row;
        AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
    }
    else
    {
        HomeWorkViewController *vc = [self.storyboard  instantiateViewControllerWithIdentifier:@"HomeWorkViewController"];
        if (model.type == kBlackBoardNotice) {
            vc.viewControllerTag=BLViewControllerTagForNotice;
        }else if (model.type == kBlackBoardCommend)
            vc.viewControllerTag=BLViewControllerTagForPraise;
        else if (model.type == kBlackBoardHomeWork)
            vc.viewControllerTag=BLViewControllerTagForHomeWork;
        vc.blackboardId = [NSString stringWithFormat:@"%ld",(long)model.id];
        
        AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
    }
    //    AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//    MyCollectionTableViewCell *vCell=(MyCollectionTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
